﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Little_Tower_Defense
{
    /// <summary>
    /// A component to scroll a level with the mouse wheel.
    /// </summary>
    class MouseWheelScrolling : GameComponent
    {
        public new LittleTowerDefense Game;

        int oldScrollWheelValue;
        Level level;
        Rectangle area;

        public MouseWheelScrolling(LittleTowerDefense game, Level level, Rectangle area)
            : base(game)
        {
            this.Game = game;
            this.level = level;
            this.area = area;
            MouseState mouse = Mouse.GetState();
            oldScrollWheelValue = mouse.ScrollWheelValue;
        }

        public override void Update(GameTime gameTime)
        {
            MouseState mouse = Mouse.GetState();

            if (Game.IsActive == true)
            {
                if (mouse.X > area.X && mouse.X < area.X + area.Width
                && mouse.Y > area.Y && mouse.Y < area.Y + area.Height)
                {
                    //TODO: The hole algorithm is crap, but enought for testing-purposes
                    if (mouse.ScrollWheelValue != oldScrollWheelValue)
                    {
                        level.BlockSize = Math.Min(Math.Max(5, ((mouse.ScrollWheelValue - oldScrollWheelValue) / 100) + level.BlockSize), 40);

                        oldScrollWheelValue = mouse.ScrollWheelValue;
                    }
                }
            }
        }
    }
}
